/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package estates.util;

import java.util.HashMap;
import java.util.StringTokenizer;

/** Klasa przechowuje parametry odczytane z obiektu biznesowego User
 *
 * @author Karol
 */
public class TransferUser {
    private String est = "";
    private String login = "";
    private String password = "";
    private String name = "";
    private String userType = "";
    private String additionalInf = "";
    private String regon = "";
    private String nip = "";
    private String pesel = "";
    private String mail = "";
    private String houseNr = "";
    private String street = "";
    private String city = "";
    private String postCode = "";
    private String phone = "";

    public String getAdditionalInf() {
        return additionalInf;
    }

    public void setAdditionalInf(String additionalInf) {
        this.additionalInf = additionalInf;
    }

    public HashMap<String, String> getAtrybuty() {
        return atrybuty;
    }

    public void setAtrybuty(HashMap<String, String> atrybuty) {
        this.atrybuty = atrybuty;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getHouseNr() {
        return houseNr;
    }

    public void setHouseNr(String houseNr) {
        this.houseNr = houseNr;
    }

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }

    public String getMail() {
        return mail;
    }

    public void setMail(String mail) {
        this.mail = mail;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getNip() {
        return nip;
    }

    public void setNip(String nip) {
        this.nip = nip;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getPesel() {
        return pesel;
    }

    public void setPesel(String pesel) {
        this.pesel = pesel;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getPostCode() {
        return postCode;
    }

    public void setPostCode(String postCode) {
        this.postCode = postCode;
    }

    public String getRegon() {
        return regon;
    }

    public void setRegon(String regon) {
        this.regon = regon;
    }

    public String getStreet() {
        return street;
    }

    public void setStreet(String street) {
        this.street = street;
    }

    public String getUserType() {
        return userType;
    }

    public void setUserType(String userType) {
        this.userType = userType;
    }

    public TransferUser(){};

    public TransferUser(String s){
        est = s;
        parse(est);
    }

    public String getEst() {
        return est;
    }

    public void setEst(String est) {
        this.est = est;
    }

    private HashMap<String, String> atrybuty = new HashMap();

    public TransferUser parse(){
        return this.parse(est);
    }

    public String get(String s){
        String s2 = atrybuty.get(s);
        return s2 == null ? "" : s2;
    }

    public TransferUser parse(String s){
       // System.out.println(s);
        StringTokenizer st = new StringTokenizer(s, "&");
         while (st.hasMoreTokens()) {
             String t = st.nextToken();
            // System.out.println(t);
             String[] arg = t.split("=");
        
             if(arg.length>1){
                atrybuty.put(arg[0], arg[1]);
             }else{
                atrybuty.put(arg[0], "");
             }
         }
        password = get("password");
        login = get("login");
        name = get("name");
        street = get("street");
        houseNr = get("houseNr");
        mail = get("mail");
        city = get("city");
        postCode = get("postCode");
        nip = get("nip");
        phone = get("phone");
        pesel = get("pesel");
        regon = get("regon");
        additionalInf = get("additionalInf");
        userType = get("userType");
        return this;
    }

}
